package com.jzr.board.base

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.WindowManager
import com.jzr.board.R
import com.jzr.board.view.LoadingDialog
import com.jzr.board.view.SwipeBackActivity.SwipeBackActivity

abstract class BaseActivity : SwipeBackActivity() {

    private var loadingDialog: LoadingDialog? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //取消状态栏
        window.setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN
        )
        window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        setContentView(getLayoutId())
        attachView()
        initView()

    }

    override fun onDestroy() {
        super.onDestroy()
        detachView()
    }

    private fun finishActivity() {
        overridePendingTransition(R.anim.slide_right_in, R.anim.slide_right_out)
    }

    fun startActivityIn(
        intent: Intent?,
        curAct: Activity
    ) {
        if (intent != null) {
            curAct.startActivity(intent)
            curAct.overridePendingTransition(R.anim.slide_left_in, R.anim.slide_left_out)
        }
    }

    override fun finish() {
        super.finish()
        finishActivity()
    }

    open fun showLoadingDialog() {
        dismissLoadingDialog()
        val builder:LoadingDialog.Builder =
          LoadingDialog.Builder(this)
                .setMessage("加载中...")
                .setCancelable(true)
        loadingDialog = builder.create()
        loadingDialog!!.show()




    }

    open fun dismissLoadingDialog() {
        if (null != loadingDialog && loadingDialog!!.isShowing) {
            loadingDialog!!.dismiss()
            loadingDialog = null
        }
    }

    abstract fun getLayoutId(): Int

    abstract fun attachView()

    abstract fun detachView()

    abstract fun initView()


}